home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17742 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  48 lines

  1. Newsgroups: comp.lang.c++
  2. Path: lugb.latrobe.edu.au!latcs1!woelkerl
  3. From: woelkerl@lion.cs.latrobe.edu.au (Eric Woelkerling)
  4. Subject: Pointer to Functions and Calls thereof??
  5. X-Nntp-Posting-Host: lion.cs.latrobe.edu.au
  6. Message-ID: <Dq017E.DL6@latcs1.lat.oz.au>
  7. Sender: news@latcs1.lat.oz.au (news)
  8. Organization: Comp.Sci & Comp.Eng, La Trobe Uni, Australia
  9. X-Newsreader: TIN [version 1.2 PL2]
  10. Date: Wed, 17 Apr 1996 09:04:26 GMT
  11.  
  12.  
  13.     I'm having some trouble getting a pointer to a function to work
  14. (ie.  I want to be able to point to a function and call the function with 
  15. this pointer ).  I have a situation where a number of routines are needed,  
  16. but only one will be selected for use through the entire program,  however
  17. this will change each run-time.  Is there an easy way to get a pointer to this
  18. function and call...
  19.  
  20.  
  21.     So far - I've only got as far as..
  22.  
  23.     void    func1(void){various bits}
  24.     void    func2(void){various bits}
  25.  
  26.     void    main()
  27.     {    void    *a[1];
  28.  
  29.         a[0]=func1;
  30.         a[1]=func2;
  31.  
  32.         (*a[0])();
  33.         (*a[1])();
  34.     }
  35.  
  36.  
  37.  
  38.     What is the obvious thing I am missing here?? This is on a PC
  39. using Borland C++.  It tells me that (*a[1])() is "not an allowed type".
  40.  
  41.     Any Ideas?
  42.  
  43.     Please email me directly..        Thanks!
  44.     Eric Woelkerling..
  45.     woelkerl@lion.lat.oz.au
  46.  
  47.  
  48.